package com.wxzz.elearning.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

public class RedisUtil {

    @Autowired
    private RedisTemplate redisTemplate;

    public  <T> T getObject(String key, Class<T> clazz) {
        Object valueObj = redisTemplate.opsForValue().get(key);
        if (clazz.isInstance(valueObj)) {
            return (T) valueObj;
        } else if (clazz == Long.class && valueObj instanceof Integer) {
            Integer obj = (Integer) valueObj;
            return (T) Long.valueOf(obj.longValue());
        }
        return null;
    }
}
